<?php
namespace Little\Controller;
use Think\Controller;
header("Content-type: text/html; charset=utf-8");

//********************详情************************

class InfoController extends Controller {
    //公开课-专题课等首页二级分类的详情列表
    public function ke_list(){
        //goods_zhu表中的 shou_type 即是展示类型id （ke_type表）
        $shou_type = I("shou_type");
        $filed = "id,img,title,nums,moneys,status";
        $list = sels("goods_zhu",$filed,"shou_type = {$shou_type}");
        $list = ke($list);
        echo json_encode(array("list"=>$list));
    }
    //课程详情
    public function ke_info(){
        $code = I("code");
        $id  = I("id");//课程id
        $user = users("users","id",$code);
        //课程详情
        $table = "goods_zhu";
        $filed = "a.*,b.name as teacher_name";
        $join  = array("a left join __TEACHER__ b on a.teacher_id = b.id");
        $where = "a.id = {$id}";
        $list  = join_one($table,$filed,$join,$where);
        //判断用户是否收藏了
        $collect_goods = sel("collect_goods","id","user_id = {$user['id']} and goods_id = {$id}");
        if($collect_goods){$list['shou'] = 1;}else{$list['shou'] = 2;}
        //开的课程  默认显示十节课
        if($list['status'] == 1){
            $ke_shu = sels("goods","","goods_zhu_id = {$id}","id desc","10");
        }
        if($list['status'] == 2){
            $ke_shu = sels("voices","","voice_zhu_id = {$id}","id desc","10");
        }
        //计算有几组十节课

        //计算开了几节课
        $count = count($ke_shu);
        if(!$count){$count = 0;}
        $list['kai'] = $count;
        echo json_encode(array("info" => $list,"ke"=>$ke_shu));
    }
    //资讯详情
    public function news(){
        $id = I('id');
        $list              = sel("news","content,phone,ke_id","id = {$id}");
        //浏览量加一
        //$nums              = $list['nums']+1;
        //$liu               = up_one("news",array("id"=>$id),array("nums"=>$nums));
        $list['content']  = img_jie("/little_program",$list['content'] );
        if($list['create_at'] >= $list['up_at']){
            $list['create_at'] = date("Y-m-d H:i",$list['create_at']);
        }else{
            $list['create_at'] = date("Y-m-d H:i",$list['up_at']);
        }
        echo json_encode(array("info"=>$list));
    }
}